package com.wisdytech.linkdcs.video.action;

import java.util.ArrayList;
import java.util.List;

import com.wisdytech.common.handler.ResourceMatchingService;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.github.pagehelper.PageInfo;
import com.wisdytech.common.bean.Filter;
import com.wisdytech.common.bean.StandardResult;
import com.wisdytech.common.bean.StandardTableResult;
import com.wisdytech.common.utils.DataTransformUtil;
import com.wisdytech.linkdcs.video.model.EquipmentVideo;
import com.wisdytech.linkdcs.video.service.IEquipmentVideoService;
import com.wisdytech.linkdcs.video.vo.EquipmentVideoVO;

import javax.servlet.http.HttpServletRequest;

/**
 * 
 * <p>ClassName: EquipVideoAction</p>
 * <p>Description: 视频监控</p>
 * <p>Author: dailibo</p>
 * <p>Date: 2017-10-10</p>
 */
@Controller
@RequestMapping("/equipment/video")
public class EquipVideoAction {
    
    @Autowired
    @Qualifier("equipmentVideoService")
    private IEquipmentVideoService equipmentVideoService;
    @Autowired
    @Qualifier("resourceMatchingService")
    private ResourceMatchingService resourceMatchingService;
    /**
     * 
     * <p>Description: 视屏设备管理</p>
     * @param model
     * @return
     */
    @RequestMapping("/equipment/index")
    public String equipmentIndex(Model model, HttpServletRequest httpRequest){
        this.resourceMatchingService.getResourceName(httpRequest,model);
        return "equipVideo/index";
    }
    
    /**
     * 
     * <p>Description: 视屏监控管理</p>
     * @param model
     * @return
     */
    @RequestMapping("/monitor/index")
    public String monitorIndex(Model model, HttpServletRequest httpRequest){
        this.resourceMatchingService.getResourceName(httpRequest,model);
        return "equipVideo/video";
    }
    
    /**
     * 分页条件查询设备终端管理页面信息列表
     * @param clientCode 终端编码
     * @param filter 分页条件
     * @return 设备终端管理页面信息列表
     */
    @RequestMapping("/listEquipmentVideoByFilter/get.mvc")
    @ResponseBody
    public StandardTableResult<EquipmentVideoVO> listEquipmentVideoByFilter(String code, Filter filter) {
       PageInfo<EquipmentVideo> equipVideos= equipmentVideoService.listEquipmentVideoByFilter(code, filter);
       //转换为前台结果集
       List<EquipmentVideo> videoList = equipVideos.getList();
       List<EquipmentVideoVO> equipVideoVOList=new ArrayList<EquipmentVideoVO>();
       for(EquipmentVideo video: videoList){
           equipVideoVOList.add(DataTransformUtil.changeEquipmentVideoVO(video));
       }
       return new StandardTableResult<EquipmentVideoVO>(equipVideos.getTotal(),equipVideoVOList);
    }
    
    
    /**
     * 保存采集终端对象
     * @param client 采集终端对象
     * @return 采集终端对象 
     */
    @RequestMapping("/saveEquipmentVideo/save.mvc")
    @ResponseBody
    public StandardResult saveEquipmentVideo(EquipmentVideo video){
        if (StringUtils.isBlank(video.getPkId())) {
          return  equipmentVideoService.addEquipmentVideo(video);
        }else{
           return equipmentVideoService.updateEquipmentVideo(video);
        }
    }
    
    /**
     * 通过主键id查询对应的采集终端信息
     * @param pkId 主键id
     * @return 采集终端信息对象
     */
    @RequestMapping("/getEquipmentVideoById/get.mvc")
    @ResponseBody
    public EquipmentVideoVO getEquipmentVideoById(String pkId){
        EquipmentVideo video = new EquipmentVideo();
        video = equipmentVideoService.getEquipmentVideoById(pkId);
        EquipmentVideoVO equipVideoVO = new EquipmentVideoVO();
        equipVideoVO = DataTransformUtil.changeEquipmentVideoVO(video);
        return equipVideoVO;
    }
    /**
     * 通过主键id删除对应的视频设备管理信息
     * @param pkId 主键id
     * @return 采集终端信息对象
     */
    @RequestMapping("/delEquipmentVideoById/del.mvc")
    @ResponseBody
    public StandardResult delEquipmentVideoById(String pkId) {
        return equipmentVideoService.delEquipmentVideoById(pkId);
    }
    
    
    
    
    
    
    

}
